<?php
	//登陆
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = '';

		function do_get()
		{
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'server.HTTP_REFERER' ) );
			echo $template->parse( 'login.php' );
		}

		function do_post()
		{
			if ( isset( $this->input['user'] ) && isset( $this->input['passwd'] ) && isset( $this->input['code'] ) )
			{
				$cookie = load( 'cookie' );
				if ( md5( "verifyid_" . $this->input['code'] ) == $cookie->get( 'VerifyId' ) )
				{
					unset( $this->input['code'] );

					$account = load( 'biz.account' );
					$login_result = $account->login( $this->input );

					if ( $login_result['status'] == 0 )
					{
						$account_id = $login_result['account_id'];

						$operate_log = load( 'biz.operate_log' );
						$operate_log->add( array( 'account_id' => $account_id, 'memo' => '', 'privilege_id' => 4 ) );

						$login_result['success'] = '1';
						echo json_encode( $login_result );
					}
					else
					{
						$text = array( '1' => '参数错误', '2' => '用户名或密码错误', '3' => '用户被冻结', '4' => '用户被删除', '5' => '用户导入失败', '6' => '状态未知' );
						$login_result['success'] = '0';
						$login_result['memo'] = isset( $text[$login_result['status']] ) ? $text[$login_result['status']] : '未知的状态';
						echo json_encode( $login_result );
					}
				}
				else
				{
					$login_result = array();
					$login_result['success'] = '0';
					$login_result['memo'] = '验证码错误';
					echo json_encode( $login_result );
				}
			}
			else
			{
				$this->do_get();
			}
		}
	}

	$action = new action();
	$action->run();
?>